package com.atguigu.yygh.controller;

import com.atguigu.yygh.feign.CmnFeign;
import com.atguigu.yygh.model.hosp.HospitalSet;
import com.atguigu.yygh.result.Result;
import com.atguigu.yygh.service.HospitalService;
import com.atguigu.yygh.service.HospitalSetService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "2.医院管理API接口")
@RestController
@RequestMapping("/api/hosp")
public class ApiController {

    @Autowired
    private HospitalService hospitalService;

    @Autowired
    private HospitalSetService hospitalSetService;

    //此方法用的为mongoDB数据库
    @ApiOperation(value = "1.mongoDB，获取所有医院设置")
    @GetMapping("/findAll")
    public Result findAllHosptial(){
        List<HospitalSet> list = hospitalService.findall();
        return Result.ok(list);
    }


    //2.查询所有医院的操作,改造之后的方法,等学习过springcatch和redis缓存后，我们可以把这个也用一下缓存,别忘了配redis
//    @Cacheable(value = "hosptial",keyGenerator = "keyGenerator")
    @ApiOperation(value = "2.mysql,获取所有医院设置")
    @GetMapping("/findall")
    public Result findAllHosptialSet(){
        List<HospitalSet> list = hospitalSetService.list();
        return Result.ok(list);
    }

    //3 根据id获取医院设置
    @ApiOperation(value = "3.根据id获取医院设置")
    @GetMapping("/getH/{id}")
    public Result getH(@PathVariable Long id) {
        HospitalSet hospitalSet = hospitalSetService.getById(id);
        return Result.ok(hospitalSet);
    }


    @Autowired
    private CmnFeign cmnFeign;
    //4.nacos远程调用的方法：返回一句话
    @ApiOperation(value = "4.nacos远程调用的方法：返回一句话")
    @GetMapping("/getString")
    public String getgetString() {
        return cmnFeign.getString();
    }


}